package com.jinghui.xiaoyuanliao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jinghui.xiaoyuanliao.R;
import com.jinghui.xiaoyuanliao.bean.ListBean;

import java.util.List;

/**
 * Created by pc on 2016/11/7.
 */

public class DrawerAdapter extends BaseAdapter {
    private List<ListBean> mDatas;
    private Context mContext;
    private final LayoutInflater mInflater;

    public DrawerAdapter(List<ListBean> listDatas, Context context){
        this.mDatas = listDatas;
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return mDatas != null ? mDatas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return mDatas != null ? mDatas.get(position):0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = mInflater.inflate(R.layout.main_list_item,parent,false);
        ImageView img = (ImageView) convertView.findViewById(R.id.drawer_img);
        img.setBackgroundResource(mDatas.get(position).getImg());
        TextView txt = (TextView) convertView.findViewById(R.id.drawer_text);
        txt.setText(mDatas.get(position).getName());
        return convertView;
    }
}
